package com.java.yz.day11.ketang;

import java.util.Objects;

public class Teacher2 implements Comparable<Teacher2>{
    private String name;
    private int age;

    public Teacher2() {
    }

    public Teacher2(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }


    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    //这里就重写了compareTo()方法，这个是自然排序
    @Override
    public int compareTo(Teacher2 o) {
        //决定它的排序，看返回值的正负和0，负的话就放在根的左边 正的话就放在根的右边 0的话就不放
        //return 0;
        //具体返回啥要看具体的需求
        //按照年龄从小到大的顺序的排序
        //this相当于传进来的元素  --k
        //o 相当于根节点的元素
        //主要条件： 从小到大的顺序
        int i1 = this.getAge()-o.getAge();
        int i2 = (i1==0)?this.getName().compareTo(o.getName()):i1;
        return i2;
    }
}
